package com.yc.cloud.cloudindex.web;

import com.yc.cloud.cloudindex.bean.Result;
import com.yc.cloud.cloudindex.bean.User;
import com.yc.cloud.cloudindex.web.feign.IUserAction;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
public class IndexAction {
    @RequestMapping("index")
    public String order(HttpServletRequest request){
        int port=request.getServerPort();
        return "index:"+port;
    }

    @Resource
    private RestTemplate restTemplate;

//    @RequestMapping("index-user")
//    public String user(){
//        String url="http://127.0.0.1:8001/user";
//        String object=restTemplate.getForObject(url,String.class);
//        return "index: "+object;
//    }
//
//    @RequestMapping("index-order")
//    public String order(){
//        String url="http://127.0.0.1:8002/order";
//        String object=restTemplate.getForObject(url,String.class);
//        return "index: "+object;
//    }

    @RequestMapping("index-user1")
    public String user1(){
        String url="http://cloud-user/user";
        String object=restTemplate.getForObject(url,String.class);
        return "index: "+object;
    }

    @RequestMapping("index-order1")
    public String order1(){
        String url="http://cloud-order/order";
        String object=restTemplate.getForObject(url,String.class);
        return "index: "+object;
    }

    @Resource
    private IUserAction iUserAction;
    @RequestMapping("index-user2")
    public String user2(){
        return "index : feign ："+iUserAction.user();
    }

    @RequestMapping("add")
    public String user3(int a,int b){
        return "index : feign ："+iUserAction.add(a,b);
    }

    @RequestMapping("div")
    public Result div(int a, int b){
        return iUserAction.div(a,b);
    }

    @RequestMapping("reg")
    public Result reg(User user){
        return iUserAction.reg(user);
    }

    @RequestMapping("div1")
    public double div1(int a){
        return iUserAction.div1(a);
    }

    @RequestMapping("sendVcode")
    public String sendVcode(){
        return iUserAction.sendVcode();
    }
}
